package com.egor.data.repository;

import com.egor.data.entity.Order;
import com.egor.data.enums.OrderStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface OrderRepository extends JpaRepository<Order, Long> {
    @Query("select o from Order o where o.orderStatus = ?1")
    Page<Order> findByOrderStatus(OrderStatus status, Pageable pageable);

    @Query("""
           select o from Order o
           where lower(o.name) like lower(concat('%', :searchTerm, '%'))
           and o.orderStatus = :status
           """)
    Page<Order> searchByCategory(@Param("searchTerm") String searchTerm,
                                 @Param("status") OrderStatus status,
                                 Pageable pageable);
}